<template>
    <div>
        <span>签到天数：{{num}}</span>
        <button @click="signin">签到</button>
    </div>
</template>
<script>
import axios from 'axios'
export default {
    data() {
        return {
            num: 0
        }
    },
    created() {
        this.num = JSON.parse(localStorage.user).signinnum
    },
    methods: {
        signin() {
            axios.post('/api/signin', {
                phone: JSON.parse(localStorage.user).phone
            }).then(res => {
                if (res.data.code == 1) {
                    const user = JSON.parse(localStorage.user)
                    user.signinnum =  res.data.signinnum
                    localStorage.setItem("user", JSON.stringify(user))
                    // localStorage.user = JSON.stringify(user)
                    this.num = res.data.signinnum
                } else {
                    alert(res.data.msg)
                }
            })
        }
    },
}
</script>